package com.ddtj.demo1.controller;

import com.ddtj.demo1.entity.User;
import com.ddtj.demo1.dao.UserJpa;
import com.ddtj.demo1.pojo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
public class LoginController {
    @Autowired
    UserJpa userJpa;
   // @PostMapping("/login")
    public String login(LoginUser loginUser){
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        User user = new User();
        user.setUsername(loginUser.getUsername());
        Example<User> userExample = Example.of(user);
        List<User> all = userJpa.findAll(userExample);
        for (User user1 : all) {
            if(bCryptPasswordEncoder.matches(user1.getPassword(),bCryptPasswordEncoder.encode(loginUser.getPassword()))){
                return null;
            }
        }
        return null;
    }
}
